package com.huajiao.management_system.service.impl;

import com.huajiao.management_system.bean.softwarecopyrightRes;
import com.huajiao.management_system.dao.softwarecopyrightResMapper;
import com.huajiao.management_system.service.softwarecopyrightResService;
import com.huajiao.management_system.util.PageQueryUtil2;
import com.huajiao.management_system.util.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class softwarecopyrightResServiceImpl implements softwarecopyrightResService {

    @Resource
    private softwarecopyrightResMapper softwarecopyrightResmapper;
    @Override
    public PageResult selectPage(String Time, String keyword, Integer page) {
        Map param = new HashMap();
        param.put("page", page);
        param.put("limit", 7);
        param.put("Time", Time);
        param.put("keyword", keyword);
        PageQueryUtil2 pageUtil = new PageQueryUtil2(param);
        if (page == 0 ) {
            PageResult pageResult = new PageResult("错误页数！");
            return pageResult;
        }
        List<softwarecopyrightRes> softwarecopyrightResList = softwarecopyrightResmapper.selectByType(pageUtil);
        int total = softwarecopyrightResmapper.getTotal(pageUtil);
        PageResult pageResult = new PageResult(softwarecopyrightResList,total, pageUtil.getLimit(), pageUtil.getPage());
        return pageResult;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertOne(softwarecopyrightRes softwarecopyrightres) {
        return softwarecopyrightResmapper.insertSelective(softwarecopyrightres);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateOne(softwarecopyrightRes softwarecopyrightres) {
        return softwarecopyrightResmapper.updateByPrimaryKeySelective(softwarecopyrightres);
    }

    @Override
    public Boolean deleteBatch(Integer[] ids) {
        return softwarecopyrightResmapper.deleteBatch(ids) > 0;
    }

    @Override
    public List<softwarecopyrightRes> getAll(String Time, String keyword) {
        Map param = new HashMap();
        param.put("Time", Time);
        param.put("keyword", keyword);
        return softwarecopyrightResmapper.selectByKeyword(param);
    }
}
